<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="项目" prop="projectId">
        <el-select v-model="queryParams.projectId" filterable placeholder="'请选择项目'">
          <el-option
            v-for="item1 in projectList"
            :key="item1.id"
            :label="item1.name"
            :value="item1.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="车位编号" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入车位编号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="车场" prop="parklotName">
        <el-input
          v-model="queryParams.parklotName"
          placeholder="请输入车场"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.berth_park_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="时间" prop="dateRange">
        <el-date-picker
          v-model="queryParams.dateRange"
          style="width: 333px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00','23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="项目" align="center" prop="projectName" />
      <el-table-column label="车场" align="center" prop="parklotName" />
      <el-table-column label="车位编号" align="center" prop="name" show-overflow-tooltip />
      <el-table-column label="车位状态" align="center" prop="status">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.berth_park_status" :value="row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="日上报次数" align="center" prop="dayReportCount" />
      <el-table-column label="日检测次数" align="center" prop="dayCheckCount" show-overflow-tooltip/>
      <el-table-column label="日变化次数" align="center" prop="dayChangeCount" show-overflow-tooltip/>
      <el-table-column label="更新时间" align="center" prop="updateTimeFormat" show-overflow-tooltip/>
      <!-- <el-table-column label="创建时间" align="center" prop="createTimeFormat" show-overflow-tooltip/> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getList,} from "@/api/parking/spaceInfor";
import { listAllFaParkProject,} from "@/api/config/projectPushManage";
import { getDay,getEndStartTime,YyMmDdToTimes,} from "@/utils/time";
export default {
  name: "SpaceInfor",
  dicts: ['berth_park_status',],
  data() {
    return {
      projectList:[],//项目数据
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name:null,
        status:null,
        projectName:null,
        parklotName:null,projectId:null,
        dateRange:[]
      },
    };
  },
  created() {
    this.getInitTime()
    this.listAllFaParkProject()
  },
  methods: {
    async listAllFaParkProject(){//查询返回所有项目列表
      let res = await listAllFaParkProject()
      let data = res.data || []
      this.projectList = data
      let queryParams = {...this.queryParams}
      if(data.length) queryParams.projectId = data[0].id
      this.queryParams = {...queryParams}
      this.getList();
    },
    getInitTime(){//初始化时间
      let end = getDay(0)
      let start = getDay(0)
      let time = getEndStartTime([start,end])
      let queryParams = {...this.queryParams}
      queryParams.dateRange = [time.startTime3,time.endTime4]
      this.queryParams = {...queryParams}
      return queryParams.dateRange
    },
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      let dateRange = queryParams.dateRange || []
      if(this.projectList.length && !queryParams.projectId) {
        queryParams.projectId = this.projectList[0].id
      }
      this.queryParams = {...queryParams}
      if(dateRange.length) {
        queryParams.startTime = dateRange[0]
        queryParams.endTime = dateRange[1]
      }
      delete queryParams.dateRange
      getList(queryParams).then(response => {
          this.list = response.rows || [];
          this.total = response.total || 0;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
